/*
First time? Check out the tutorial game:
https://sprig.hackclub.com/gallery/getting_started

@title: Yet Another Sprig 3D Engine
@author: None
@description: None
@tags: []
@addedOn: 2025-00-00
*/

/*
This engine was developed entirely from scratch. So even models are in other format. If you are interested in loading other models, use this Blender Python script

import bpy
import json

def rgb_to_hex(rgb):
    """Convert RGB values to a hex color string."""
    return "#{:02x}{:02x}{:02x}".format(int(rgb[0] * 255), int(rgb[1] * 255), int(rgb[2] * 255))

def get_faces_data(obj):
    """Extract face data from the given object."""
    faces_data = []
    
    # Ensure the object is a mesh
    if obj.type == 'MESH':
        mesh = obj.data
        
        # Loop through each face in the mesh
        for poly in mesh.polygons:
            # Get the vertices of the face
            vertices = [mesh.vertices[i].co for i in poly.vertices]
            # Convert vertices to a list of lists
            polygon = [[v.x, v.y, v.z] for v in vertices]
            
            # Get the material index and color
            if poly.material_index < len(mesh.materials):
                material = mesh.materials[poly.material_index]
                if material.diffuse_color:
                    color = rgb_to_hex(material.diffuse_color[:3])  # Ignore alpha for color
                else:
                    color = "#ffffff"  # Default to white if no color
            else:
                color = "#ffffff"  # Default to white if no material
            
            # Append the face data
            faces_data.append({"polygon": polygon, "color": color})
    
    return faces_data

def export_scene_to_json():
    """Export the current scene to JSON format."""
    all_faces_data = []
    
    # Loop through all selected objects
    for obj in bpy.context.selected_objects:
        faces_data = get_faces_data(obj)
        all_faces_data.extend(faces_data)
    
    # Convert to JSON
    json_data = json.dumps(all_faces_data)
    
    # Print the JSON to the console
    print("----\n\n\n\n")
    print(json_data)

# Run the export function
export_scene_to_json()
*/

// Description: A proof that sprig can handle FULL 3d graphics, and it's possible to make a 3d game.
/*
Controls:
W - Bigger fish
A - Move left
S - Smaller fish
D - Move right
J - Rotate X
K - Rotate Y
L - Rotate Z
*/

const red = "r"
const green = "g"
const blue = "b"
const pink = "p"
const yellow = "y"
const black = "d"
const cccccc = "c"

setLegend(
  [ red, bitmap`
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333
3333333333333333`],
  [ green, bitmap`
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444
4444444444444444`],
  [ blue, bitmap`
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555
5555555555555555`],
  [ pink, bitmap`
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888
8888888888888888`],
  [ yellow, bitmap`
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666
6666666666666666`],
  [ black, bitmap`
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000
0000000000000000`],
  [ cccccc, bitmap`
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212
2121212121212121
1212121212121212`]
)

setSolids([])

let level = 0
const levels = [
  map`
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................`
]

setMap(levels[level])

// Based on Sapbot S3D (My own 3d renderer)
function rotateX(point, angle) {
    const rad = angle * Math.PI / 180;
    const cos = Math.cos(rad);
    const sin = Math.sin(rad);
    return [
        point[0],
        point[1] * cos - point[2] * sin,
        point[1] * sin + point[2] * cos
    ];
}

function rotateY(point, angle) {
    const rad = angle * Math.PI / 180;
    const cos = Math.cos(rad);
    const sin = Math.sin(rad);
    return [
        point[0] * cos + point[2] * sin,
        point[1],
        -point[0] * sin + point[2] * cos
    ];
}

function rotateZ(point, angle) {
    const rad = angle * Math.PI / 180;
    const cos = Math.cos(rad);
    const sin = Math.sin(rad);
    return [
        point[0] * cos - point[1] * sin,
        point[0] * sin + point[1] * cos,
        point[2]
    ];
}

var rotx = 0
var roty = 0
var rotz = 0
var engine = {};

function xyzToXY(x, y, z) {
    const halfZ = z * 0.5; // Use multiplication by 0.5 instead of division
    return [x + halfZ, y + halfZ];
}

function averageZ(face) {
    let totalZ = 0;
    const length = face.length;

    for (let i = 0; i < length; i++) {
        totalZ += face[i][2];
    }

    return totalZ / length;
}

engine.render = function(faces) {
    // Precompute average Z for sorting
    const averageZs = faces.map(face => averageZ(face.polygon));
    
    // Sort faces by precomputed average Z
    faces.sort((a, b) => averageZs[faces.indexOf(a)] - averageZs[faces.indexOf(b)]);

    const result = new Array(faces.length); // Preallocate result array

    for (let i = 0; i < faces.length; i++) {
        const { polygon, color } = faces[i];
        const transformedPolygon = polygon; // Assuming vshader returns an array of vertices
        const projectedPolygon = new Array(transformedPolygon.length); // Preallocate projectedPolygon array

        for (let j = 0; j < transformedPolygon.length; j++) {
            const vertex = transformedPolygon[j];
            projectedPolygon[j] = xyzToXY(vertex[0], vertex[1], vertex[2]);
        }

        result[i] = {
            polygon: projectedPolygon,
            color: color // Use transformedPolygon for color shader
        };
    }

    return result;
};

var basefigure = [{"polygon": [[-11.72659969329834, 0.0, 0.5761709809303284], [-12.902199745178223, 0.0, 1.042009949684143], [-8.83887004852295, 0.0, 0.3081049919128418], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478], [-11.27489948272705, 0.0, 0.057128001004457474], [-11.179200172424316, 0.0, 0.23925699293613434], [-12.01609992980957, 0.0, 0.4326150119304657]], "color": "#cccccc"}, {"polygon": [[2.871569871902466, -0.1909179985523224, -0.5954620242118835], [3.0580999851226807, -0.16162100434303284, -0.6696810126304626], [3.021479845046997, -0.13867199420928955, -0.4572789967060089]], "color": "#cccccc"}, {"polygon": [[1.8934499025344849, 0.00022699999681208283, 0.1534470021724701], [1.8862498998641968, -0.2250179946422577, -0.17053799331188202], [1.8021799325942993, -0.1757809966802597, -0.374673992395401], [1.6599299907684326, 0.0, -0.44718000292778015]], "color": "#cccccc"}, {"polygon": [[1.8862498998641968, -0.2250179946422577, -0.17053799331188202], [1.8934499025344849, 0.00022699999681208283, 0.1534470021724701], [2.801219940185547, -0.1845179945230484, 0.12432499974966049], [2.1840100288391113, -0.27848100662231445, -0.0370820015668869]], "color": "#cccccc"}, {"polygon": [[3.8369100093841553, -0.09081999957561493, -0.9494659900665283], [3.8413000106811523, -0.08544900268316269, -1.0207599401474], [3.8413000106811523, 0.08544900268316269, -1.0207599401474], [3.8369100093841553, 0.09081999957561493, -0.9494659900665283]], "color": "#cccccc"}, {"polygon": [[3.0766499042510986, -0.12304700165987015, -0.787356972694397], [3.4111199378967285, 0.0, -0.8952670097351074], [2.7358298301696777, 0.0, -0.772707998752594], [1.6599299907684326, 0.0, -0.44718000292778015], [1.8021799325942993, -0.1757809966802597, -0.374673992395401]], "color": "#cccccc"}, {"polygon": [[3.319819927215576, -0.21875, -0.834231972694397], [1.9444799423217773, -0.3626039922237396, -0.3017309904098511], [2.8607699871063232, -0.24943800270557404, 0.008580000139772892], [3.507200002670288, 0.0007849999819882214, 0.10064200311899185], [3.5580198764801025, 0.0008030000026337802, 0.1997459977865219], [3.395939826965332, -0.11546400189399719, 0.1768530011177063], [1.7745399475097656, -0.4789620041847229, -0.1236250028014183], [-0.12793000042438507, -0.7719730138778687, -0.005371000152081251], [0.053711000829935074, -0.5502930283546448, -0.6528319716453552], [3.671379804611206, -0.09033200144767761, -1.0539599657058716], [3.8413000106811523, -0.08544900268316269, -1.0207599401474], [3.8369100093841553, -0.09081999957561493, -0.9494659900665283]], "color": "#cccccc"}, {"polygon": [[3.521969795227051, 0.05761700123548508, -0.8444859981536865], [3.521969795227051, -0.05761700123548508, -0.8444859981536865], [3.5175700187683105, 0.0, -0.6774929761886597]], "color": "#cccccc"}, {"polygon": [[1.8021799325942993, -0.1757809966802597, -0.374673992395401], [1.8862498998641968, -0.2250179946422577, -0.17053799331188202], [2.1840100288391113, -0.27848100662231445, -0.0370820015668869], [1.944409966468811, -0.22344399988651276, -0.30174198746681213], [3.2983298301696777, -0.109375, -0.7678250074386597], [3.0766499042510986, -0.12304700165987015, -0.787356972694397]], "color": "#cccccc"}, {"polygon": [[3.4125900268554688, 0.06787099689245224, -0.632082998752594], [3.457509994506836, 0.0703129991889, -0.8205599784851074], [3.393549919128418, 0.1362299919128418, -0.7990750074386597]], "color": "#cccccc"}, {"polygon": [[3.2983298301696777, 0.109375, -0.7678250074386597], [3.4125900268554688, 0.06787099689245224, -0.632082998752594], [3.393549919128418, 0.1362299919128418, -0.7990750074386597]], "color": "#cccccc"}, {"polygon": [[3.0766499042510986, 0.12304700165987015, -0.787356972694397], [3.4111199378967285, 0.0, -0.8952670097351074], [3.4643499851226807, 0.0, -0.8161649703979492]], "color": "#cccccc"}, {"polygon": [[3.2983298301696777, 0.109375, -0.7678250074386597], [3.0766499042510986, 0.12304700165987015, -0.787356972694397], [3.4643499851226807, 0.0, -0.8161649703979492]], "color": "#cccccc"}, {"polygon": [[3.224599838256836, 0.11425799876451492, -0.5129429697990417], [3.27197003364563, 0.12255899608135223, -0.7600129842758179], [3.207509994506836, 0.16894499957561493, -0.7302280068397522]], "color": "#cccccc"}, {"polygon": [[3.1020398139953613, 0.15673799812793732, -0.6882359981536865], [3.224599838256836, 0.11425799876451492, -0.5129429697990417], [3.207509994506836, 0.16894499957561493, -0.7302280068397522]], "color": "#cccccc"}, {"polygon": [[3.2571699619293213, 0.08565999567508698, 0.08119700103998184], [3.375349998474121, 0.043219998478889465, 0.0899450033903122], [3.3699100017547607, 0.045660000294446945, -0.08485700190067291]], "color": "#cccccc"}, {"polygon": [[2.6240198612213135, -0.21240200102329254, -0.5051299929618835], [2.843250036239624, -0.19238300621509552, -0.5886260271072388], [2.7880799770355225, -0.1752929985523224, -0.3747589886188507]], "color": "#cccccc"}, {"polygon": [[2.3618099689483643, -0.2421880066394806, -0.4011259973049164], [2.598140001296997, -0.21972699463367462, -0.49341100454330444], [2.4970598220825195, -0.20458999276161194, -0.3083530068397522]], "color": "#cccccc"}, {"polygon": [[3.5175700187683105, 0.0, -0.6774929761886597], [3.521969795227051, -0.05761700123548508, -0.8444859981536865], [3.5493099689483643, 0.0, -0.8527860045433044]], "color": "#cccccc"}, {"polygon": [[3.521969795227051, 0.05761700123548508, -0.8444859981536865], [3.5175700187683105, 0.0, -0.6774929761886597], [3.5493099689483643, 0.0, -0.8527860045433044]], "color": "#cccccc"}, {"polygon": [[3.393549919128418, -0.1362299919128418, -0.7990750074386597], [3.457509994506836, -0.0703129991889, -0.8205599784851074], [3.4125900268554688, -0.06787099689245224, -0.632082998752594]], "color": "#cccccc"}, {"polygon": [[3.2983298301696777, -0.109375, -0.7678250074386597], [3.393549919128418, -0.1362299919128418, -0.7990750074386597], [3.4125900268554688, -0.06787099689245224, -0.632082998752594]], "color": "#cccccc"}, {"polygon": [[3.4111199378967285, 0.0, -0.8952670097351074], [3.0766499042510986, -0.12304700165987015, -0.787356972694397], [3.4643499851226807, 0.0, -0.8161649703979492]], "color": "#cccccc"}, {"polygon": [[3.207509994506836, -0.16894499957561493, -0.7302280068397522], [3.27197003364563, -0.12255899608135223, -0.7600129842758179], [3.224599838256836, -0.11425799876451492, -0.5129429697990417]], "color": "#cccccc"}, {"polygon": [[3.1020398139953613, -0.15673799812793732, -0.6882359981536865], [3.207509994506836, -0.16894499957561493, -0.7302280068397522], [3.224599838256836, -0.11425799876451492, -0.5129429697990417]], "color": "#cccccc"}, {"polygon": [[2.871569871902466, 0.19043000042438507, -0.5954620242118835], [3.021479845046997, 0.13867199420928955, -0.4572789967060089], [3.0580999851226807, 0.16162100434303284, -0.6696810126304626]], "color": "#cccccc"}, {"polygon": [[-4.100100040435791, 0.0, -0.8486329913139343], [-7.445309638977051, 0.0, -0.4794920086860657], [-9.037599563598633, 0.0, -0.3818359971046448], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478], [-4.132319927215576, 0.6679689884185791, -0.021484000608325005]], "color": "#cccccc"}, {"polygon": [[2.7880799770355225, 0.1752929985523224, -0.3747589886188507], [2.6240198612213135, 0.21240200102329254, -0.5051299929618835], [2.843250036239624, 0.19238300621509552, -0.5886260271072388]], "color": "#cccccc"}, {"polygon": [[2.4970598220825195, 0.20458999276161194, -0.3083530068397522], [2.3618099689483643, 0.2421880066394806, -0.4011259973049164], [2.598140001296997, 0.21972699463367462, -0.49341100454330444]], "color": "#cccccc"}, {"polygon": [[3.2983298301696777, -0.109375, -0.7678250074386597], [3.4125900268554688, -0.06787099689245224, -0.632082998752594], [3.457509994506836, -0.0703129991889, -0.8205599784851074]], "color": "#cccccc"}, {"polygon": [[3.1020398139953613, -0.15673799812793732, -0.6882359981536865], [3.224599838256836, -0.11425799876451492, -0.5129429697990417], [3.27197003364563, -0.12255899608135223, -0.7600129842758179]], "color": "#cccccc"}, {"polygon": [[2.871569871902466, -0.1909179985523224, -0.5954620242118835], [3.021479845046997, -0.13867199420928955, -0.4572789967060089], [3.0580999851226807, -0.16162100434303284, -0.6696810126304626]], "color": "#cccccc"}, {"polygon": [[2.6240198612213135, -0.21240200102329254, -0.5051299929618835], [2.7880799770355225, -0.1752929985523224, -0.3747589886188507], [2.843250036239624, -0.19238300621509552, -0.5886260271072388]], "color": "#cccccc"}, {"polygon": [[2.3618099689483643, -0.2421880066394806, -0.4011259973049164], [2.4970598220825195, -0.20458999276161194, -0.3083530068397522], [2.598140001296997, -0.21972699463367462, -0.49341100454330444]], "color": "#cccccc"}, {"polygon": [[3.4125900268554688, 0.06787099689245224, -0.632082998752594], [3.2983298301696777, 0.109375, -0.7678250074386597], [3.457509994506836, 0.0703129991889, -0.8205599784851074]], "color": "#cccccc"}, {"polygon": [[3.224599838256836, 0.11425799876451492, -0.5129429697990417], [3.1020398139953613, 0.15673799812793732, -0.6882359981536865], [3.27197003364563, 0.12255899608135223, -0.7600129842758179]], "color": "#cccccc"}, {"polygon": [[3.021479845046997, 0.13867199420928955, -0.4572789967060089], [2.871569871902466, 0.19043000042438507, -0.5954620242118835], [3.0580999851226807, 0.16162100434303284, -0.6696810126304626]], "color": "#cccccc"}, {"polygon": [[-7.73583984375, 0.0, 0.5527340173721313], [-7.428219795227051, 0.0, 0.69091796875], [-7.602540016174316, 0.0, 0.89404296875], [-7.354000568389893, 0.0, 1.0122100114822388], [-7.843109607696533, 0.0, 1.5635600090026855], [-5.729000091552734, 0.0, 0.7001950144767761]], "color": "#cccccc"}, {"polygon": [[-0.38933300971984863, 0.6569139957427979, -0.41693899035453796], [-0.3702789843082428, 0.7496749758720398, -0.23676399886608124], [-0.17431600391864777, 0.6767579913139343, -0.006835999898612499], [0.025390999391674995, 0.4130859971046448, -0.6538090109825134], [-4.108890056610107, 0.3940429985523224, -0.6069340109825134], [-4.132319927215576, 0.6679689884185791, -0.021484000608325005], [-0.9501950144767761, 0.7592769861221313, 0.026366999372839928], [-0.17431600391864777, 0.6767579913139343, -0.006835999898612499], [-0.3449670076370239, 0.6836680173873901, -0.10785699635744095]], "color": "#cccccc"}, {"polygon": [[1.677259922027588, -0.3103939890861511, 0.1833070069551468], [1.7704899311065674, -0.31524500250816345, 0.0895249992609024], [1.9033299684524536, -0.41187798976898193, 0.081666000187397], [1.4112999439239502, -0.6737679839134216, 0.26591798663139343], [0.9581760168075562, -0.6177719831466675, 0.3251569867134094], [1.2163900136947632, -0.41895198822021484, 0.2723340094089508], [1.445259928703308, -0.16545499861240387, 0.12918800115585327]], "color": "#cccccc"}, {"polygon": [[0.9577490091323853, 0.617579996585846, 0.3251569867134094], [1.2160999774932861, 0.418938010931015, 0.2723340094089508], [1.44514000415802, 0.1655990034341812, 0.12918800115585327], [1.2150800228118896, 0.35741499066352844, 0.0960640013217926]], "color": "#cccccc"}, {"polygon": [[1.1309000253677368, -0.5117560029029846, 0.05458899959921837], [1.2153300046920776, -0.35742899775505066, 0.0960640013217926], [0.9581760168075562, -0.6177719831466675, 0.3251569867134094]], "color": "#cccccc"}, {"polygon": [[1.7575899362564087, 0.5241069793701172, 0.3385530114173889], [1.8806999921798706, 0.37229299545288086, 0.36487698554992676], [1.9030499458312988, 0.412339985370636, 0.081666000187397], [1.7043099403381348, 0.5685210227966309, 0.21503600478172302]], "color": "#cccccc"}, {"polygon": [[1.8021799325942993, 0.1757809966802597, -0.374673992395401], [1.6599299907684326, 0.0, -0.44718000292778015], [2.7358298301696777, 0.0, -0.772707998752594], [3.4111199378967285, 0.0, -0.8952670097351074], [3.0766499042510986, 0.12304700165987015, -0.787356972694397]], "color": "#cccccc"}, {"polygon": [[-1.456279993057251, -1.3592900037765503, -0.13617800176143646], [-0.7519530057907104, -0.917481005191803, -0.5712890028953552], [-0.38933300971984863, -0.6569139957427979, -0.41693899035453796], [-0.3702789843082428, -0.7496749758720398, -0.23676399886608124], [-0.3449670076370239, -0.6836680173873901, -0.10785699635744095]], "color": "#cccccc"}, {"polygon": [[1.9030499458312988, 0.412339985370636, 0.081666000187397], [1.7702699899673462, 0.3156149983406067, 0.0895249992609024], [1.6770399808883667, 0.310699999332428, 0.1833070069551468], [1.44514000415802, 0.1655990034341812, 0.12918800115585327], [1.2160999774932861, 0.418938010931015, 0.2723340094089508], [0.9577490091323853, 0.617579996585846, 0.3251569867134094], [1.410830020904541, 0.6738889813423157, 0.2659189999103546]], "color": "#cccccc"}, {"polygon": [[1.6770399808883667, 0.310699999332428, 0.1833070069551468], [1.7702699899673462, 0.3156149983406067, 0.0895249992609024], [1.44514000415802, 0.1655990034341812, 0.12918800115585327]], "color": "#cccccc"}, {"polygon": [[-12.902199745178223, 0.0, 1.042009949684143], [-11.72659969329834, 0.0, 0.5761709809303284], [-12.01609992980957, 0.0, 0.4326150119304657], [-11.179200172424316, 0.0, 0.23925699293613434], [-11.27489948272705, 0.0, 0.057128001004457474], [-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-8.83887004852295, 0.0, 0.3081049919128418]], "color": "#cccccc"}, {"polygon": [[1.8861199617385864, 0.22500000894069672, -0.17057399451732635], [2.1838200092315674, 0.27913698554039, -0.0370820015668869], [2.8010900020599365, 0.18559999763965607, 0.12432499974966049], [1.8934499025344849, 0.00022699999681208283, 0.1534470021724701]], "color": "#cccccc"}, {"polygon": [[0.16943399608135223, 0.5043950080871582, 0.7456049919128418], [-0.17431600391864777, 0.6767579913139343, -0.006835999898612499], [-0.9501950144767761, 0.7592769861221313, 0.026366999372839928], [-4.132319927215576, 0.6679689884185791, -0.021484000608325005], [-4.154299736022949, 0.3940429985523224, 0.6005859971046448]], "color": "#cccccc"}, {"polygon": [[1.2163900136947632, -0.41895198822021484, 0.2723340094089508], [0.9581760168075562, -0.6177719831466675, 0.3251569867134094], [1.2153300046920776, -0.35742899775505066, 0.0960640013217926], [1.445259928703308, -0.16545499861240387, 0.12918800115585327]], "color": "#cccccc"}, {"polygon": [[3.3055498600006104, -0.052018001675605774, 0.07532200217247009], [3.3055098056793213, 0.053449999541044235, 0.07532200217247009], [2.1867098808288574, 0.3035520017147064, -0.11667399853467941], [1.9442899227142334, 0.22382000088691711, -0.3017739951610565], [1.9442698955535889, 0.3629799783229828, -0.30178600549697876], [2.860599994659424, 0.25056201219558716, 0.008580000139772892], [3.507200002670288, 0.0007849999819882214, 0.10064200311899185], [2.8607699871063232, -0.24943800270557404, 0.008580000139772892], [1.9444799423217773, -0.3626039922237396, -0.3017309904098511], [1.944409966468811, -0.22344399988651276, -0.30174198746681213], [2.186919927597046, -0.3028939962387085, -0.11667399853467941]], "color": "#cccccc"}, {"polygon": [[3.319819927215576, -0.21875, -0.834231972694397], [3.8369100093841553, -0.09081999957561493, -0.9494659900665283], [2.814929962158203, -0.2851560115814209, -0.5656769871711731], [2.346179962158203, -0.3505859971046448, -0.3855009973049164], [1.9444799423217773, -0.3626039922237396, -0.3017309904098511]], "color": "#cccccc"}, {"polygon": [[-0.12793000042438507, 0.7719730138778687, -0.005371000152081251], [0.053711000829935074, 0.5502930283546448, -0.6528319716453552], [0.025390999391674995, 0.4130859971046448, -0.6538090109825134], [-0.17431600391864777, 0.6767579913139343, -0.006835999898612499]], "color": "#cccccc"}, {"polygon": [[-7.445309638977051, 0.0, -0.4794920086860657], [-4.100100040435791, 0.0, -0.8486329913139343], [-4.132319927215576, -0.6679689884185791, -0.021484000608325005], [-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-9.037599563598633, 0.0, -0.3818359971046448]], "color": "#cccccc"}, {"polygon": [[0.9577490091323853, 0.617579996585846, 0.3251569867134094], [1.2150800228118896, 0.35741499066352844, 0.0960640013217926], [1.1305400133132935, 0.5116829872131348, 0.05458899959921837]], "color": "#cccccc"}, {"polygon": [[3.23475980758667, -0.09745299816131592, 0.0719280019402504], [3.0853500366210938, -0.12435999512672424, 0.04805399850010872], [3.2317798137664795, -0.11063800007104874, -0.10726999491453171]], "color": "#cccccc"}, {"polygon": [[-2.7475600242614746, 0.0, 1.1728500127792358], [-2.91405987739563, 0.0, 1.4057599306106567], [-2.8022499084472656, 0.0, 1.500980019569397], [-2.9940998554229736, 0.0, 1.8645399808883667], [-1.6791999340057373, 0.0, 0.9619140028953552], [-2.6708998680114746, 0.0, 0.9462890028953552], [-2.8691399097442627, 0.0, 1.0835000276565552]], "color": "#cccccc"}, {"polygon": [[2.3618099689483643, 0.2421880066394806, -0.4011259973049164], [2.4970598220825195, 0.20458999276161194, -0.3083530068397522], [2.598140001296997, 0.21972699463367462, -0.49341100454330444]], "color": "#cccccc"}, {"polygon": [[3.012539863586426, -0.16149400174617767, -0.14576900005340576], [3.0497100353240967, -0.1448809951543808, 0.047088999301195145], [2.9906399250030518, -0.185916006565094, 0.035392001271247864]], "color": "#cccccc"}, {"polygon": [[2.917879819869995, -0.18154700100421906, 0.02418600022792816], [3.012539863586426, -0.16149400174617767, -0.14576900005340576], [2.9906399250030518, -0.185916006565094, 0.035392001271247864]], "color": "#cccccc"}, {"polygon": [[1.8861199617385864, 0.22500000894069672, -0.17057399451732635], [1.8934499025344849, 0.00022699999681208283, 0.1534470021724701], [1.6599299907684326, 0.0, -0.44718000292778015], [1.8021799325942993, 0.1757809966802597, -0.374673992395401]], "color": "#cccccc"}, {"polygon": [[3.8413000106811523, 0.08544900268316269, -1.0207599401474], [3.8413000106811523, -0.08544900268316269, -1.0207599401474], [3.671379804611206, -0.09033200144767761, -1.0539599657058716], [3.6835899353027344, 0.0, -1.0622600317001343], [2.188969850540161, 0.0, -0.7973629832267761], [1.8540000915527344, 0.0, -0.7602530121803284], [1.5932899713516235, 0.0, -0.7285730242729187], [1.212459921836853, 0.0, -0.7765659689903259], [0.4111329913139343, 0.0, -0.8847659826278687], [0.025390999391674995, 0.4130859971046448, -0.6538090109825134], [0.053711000829935074, 0.5502930283546448, -0.6528319716453552]], "color": "#cccccc"}, {"polygon": [[-4.163569927215576, 0.0, 0.84375], [-4.132319927215576, 0.6679689884185791, -0.021484000608325005], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478]], "color": "#cccccc"}, {"polygon": [[2.186919927597046, -0.3028939962387085, -0.11667399853467941], [2.1840100288391113, -0.27848100662231445, -0.0370820015668869], [2.801219940185547, -0.1845179945230484, 0.12432499974966049], [3.3055498600006104, -0.052018001675605774, 0.07532200217247009]], "color": "#cccccc"}, {"polygon": [[2.3915200233459473, -0.28768599033355713, -0.06840399652719498], [2.506700038909912, -0.26030200719833374, -0.18465599417686462], [2.6175999641418457, -0.25586998462677, -0.024049000814557076]], "color": "#cccccc"}, {"polygon": [[2.9905099868774414, 0.18712998926639557, 0.035392001271247864], [3.049609899520874, 0.14613500237464905, 0.047088999301195145], [3.01242995262146, 0.16272400319576263, -0.14576900005340576]], "color": "#cccccc"}, {"polygon": [[2.917759895324707, 0.18271100521087646, 0.02418600022792816], [2.9905099868774414, 0.18712998926639557, 0.035392001271247864], [3.01242995262146, 0.16272400319576263, -0.14576900005340576]], "color": "#cccccc"}, {"polygon": [[2.6732499599456787, -0.22411200404167175, -0.014790999703109264], [2.7762198448181152, -0.2045450061559677, -0.1686359941959381], [2.8627099990844727, -0.1888899952173233, 0.01639300025999546]], "color": "#cccccc"}, {"polygon": [[3.2572200298309326, -0.08426100015640259, 0.08119700103998184], [3.3699498176574707, -0.044183000922203064, -0.08485700190067291], [3.375379800796509, -0.041738998144865036, 0.0899450033903122]], "color": "#cccccc"}, {"polygon": [[2.673099994659424, 0.22510600090026855, -0.014790999703109264], [2.862579822540283, 0.1900160014629364, 0.01639300025999546], [2.7760798931121826, 0.20561100542545319, -0.1686359941959381]], "color": "#cccccc"}, {"polygon": [[3.2571699619293213, 0.08565999567508698, 0.08119700103998184], [3.3699100017547607, 0.045660000294446945, -0.08485700190067291], [3.375349998474121, 0.043219998478889465, 0.0899450033903122]], "color": "#cccccc"}, {"polygon": [[2.506700038909912, -0.26030200719833374, -0.18465599417686462], [2.3915200233459473, -0.28768599033355713, -0.06840399652719498], [2.6175999641418457, -0.25586998462677, -0.024049000814557076]], "color": "#cccccc"}, {"polygon": [[2.7762198448181152, -0.2045450061559677, -0.1686359941959381], [2.6732499599456787, -0.22411200404167175, -0.014790999703109264], [2.8627099990844727, -0.1888899952173233, 0.01639300025999546]], "color": "#cccccc"}, {"polygon": [[3.012539863586426, -0.16149400174617767, -0.14576900005340576], [2.917879819869995, -0.18154700100421906, 0.02418600022792816], [3.0497100353240967, -0.1448809951543808, 0.047088999301195145]], "color": "#cccccc"}, {"polygon": [[3.2317798137664795, -0.11063800007104874, -0.10726999491453171], [3.0853500366210938, -0.12435999512672424, 0.04805399850010872], [3.23475980758667, -0.09745299816131592, 0.0719280019402504]], "color": "#cccccc"}, {"polygon": [[1.445259928703308, -0.16545499861240387, 0.12918800115585327], [1.7704899311065674, -0.31524500250816345, 0.0895249992609024], [1.677259922027588, -0.3103939890861511, 0.1833070069551468]], "color": "#cccccc"}, {"polygon": [[3.3699498176574707, -0.044183000922203064, -0.08485700190067291], [3.2572200298309326, -0.08426100015640259, 0.08119700103998184], [3.375379800796509, -0.041738998144865036, 0.0899450033903122]], "color": "#cccccc"}, {"polygon": [[2.391319990158081, 0.2884860038757324, -0.06840399652719498], [2.5065200328826904, 0.2611820101737976, -0.18465599417686462], [2.617419958114624, 0.2568260133266449, -0.024049000814557076]], "color": "#cccccc"}, {"polygon": [[2.673099994659424, 0.22510600090026855, -0.014790999703109264], [2.7760798931121826, 0.20561100542545319, -0.1686359941959381], [2.862579822540283, 0.1900160014629364, 0.01639300025999546]], "color": "#cccccc"}, {"polygon": [[2.917759895324707, 0.18271100521087646, 0.02418600022792816], [3.01242995262146, 0.16272400319576263, -0.14576900005340576], [3.049609899520874, 0.14613500237464905, 0.047088999301195145]], "color": "#cccccc"}, {"polygon": [[3.0852599143981934, 0.12563998997211456, 0.04805399850010872], [3.2316999435424805, 0.11201799660921097, -0.10726999491453171], [3.2346999645233154, 0.09883599728345871, 0.0719280019402504]], "color": "#cccccc"}, {"polygon": [[2.186919927597046, -0.3028939962387085, -0.11667399853467941], [1.944409966468811, -0.22344399988651276, -0.30174198746681213], [2.1840100288391113, -0.27848100662231445, -0.0370820015668869]], "color": "#cccccc"}, {"polygon": [[-7.251949787139893, 0.0, -0.8139650225639343], [-7.297359943389893, 0.0, -1.0063499212265015], [-7.166989803314209, 0.0, -1.1372100114822388], [-7.2927398681640625, 0.0, -1.6883900165557861], [-5.675779819488525, 0.0, -0.7148439884185791], [-7.445309638977051, 0.0, -0.4794920086860657], [-7.475100040435791, 0.0, -0.6303709745407104]], "color": "#cccccc"}, {"polygon": [[-7.166989803314209, 0.0, -1.1372100114822388], [-7.297359943389893, 0.0, -1.0063499212265015], [-7.251949787139893, 0.0, -0.8139650225639343], [-7.475100040435791, 0.0, -0.6303709745407104], [-7.445309638977051, 0.0, -0.4794920086860657], [-5.675779819488525, 0.0, -0.7148439884185791], [-7.2927398681640625, 0.0, -1.6883900165557861]], "color": "#cccccc"}, {"polygon": [[-4.163569927215576, 0.0, 0.84375], [-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-4.132319927215576, -0.6679689884185791, -0.021484000608325005]], "color": "#cccccc"}, {"polygon": [[2.8010900020599365, 0.18559999763965607, 0.12432499974966049], [3.3055098056793213, 0.053449999541044235, 0.07532200217247009], [3.3055498600006104, -0.052018001675605774, 0.07532200217247009], [2.801219940185547, -0.1845179945230484, 0.12432499974966049], [1.8934499025344849, 0.00022699999681208283, 0.1534470021724701]], "color": "#cccccc"}, {"polygon": [[1.9442899227142334, 0.22382000088691711, -0.3017739951610565], [2.1867098808288574, 0.3035520017147064, -0.11667399853467941], [2.1838200092315674, 0.27913698554039, -0.0370820015668869]], "color": "#cccccc"}, {"polygon": [[1.9442899227142334, 0.22382000088691711, -0.3017739951610565], [2.1838200092315674, 0.27913698554039, -0.0370820015668869], [1.8861199617385864, 0.22500000894069672, -0.17057399451732635], [1.8021799325942993, 0.1757809966802597, -0.374673992395401], [3.0766499042510986, 0.12304700165987015, -0.787356972694397], [3.2983298301696777, 0.109375, -0.7678250074386597]], "color": "#cccccc"}, {"polygon": [[-1.456279993057251, -1.3592900037765503, -0.13617800176143646], [-0.3449670076370239, -0.6836680173873901, -0.10785699635744095], [-0.38933300971984863, -0.6569139957427979, -0.41693899035453796], [-0.7519530057907104, -0.917481005191803, -0.5712890028953552]], "color": "#cccccc"}, {"polygon": [[2.391319990158081, 0.2884860038757324, -0.06840399652719498], [2.617419958114624, 0.2568260133266449, -0.024049000814557076], [2.5065200328826904, 0.2611820101737976, -0.18465599417686462]], "color": "#cccccc"}, {"polygon": [[0.053711000829935074, 0.5502930283546448, -0.6528319716453552], [-0.12793000042438507, 0.7719730138778687, -0.005371000152081251], [1.7741299867630005, 0.47944098711013794, -0.12415999919176102], [3.395859956741333, 0.11695799976587296, 0.1768530011177063], [3.5580198764801025, 0.0008030000026337802, 0.1997459977865219], [3.507200002670288, 0.0007849999819882214, 0.10064200311899185], [2.860599994659424, 0.25056201219558716, 0.008580000139772892], [1.9442698955535889, 0.3629799783229828, -0.30178600549697876], [3.319819927215576, 0.21875, -0.834231972694397], [3.8369100093841553, 0.09081999957561493, -0.9494659900665283], [3.8413000106811523, 0.08544900268316269, -1.0207599401474]], "color": "#cccccc"}, {"polygon": [[-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-11.266599655151367, -0.0008730000117793679, -0.27929601073265076], [-11.11769962310791, -0.0008340000058524311, -0.4765610098838806], [-11.738299369812012, -0.000590000010561198, -1.0317399501800537], [-11.58449935913086, -0.0005859999801032245, -1.023919939994812], [-12.198599815368652, -5.0999999075429514e-05, -1.700089931488037], [-9.037599563598633, 0.0, -0.3818359971046448]], "color": "#cccccc"}, {"polygon": [[2.814929962158203, 0.2851560115814209, -0.5656769871711731], [3.8369100093841553, 0.09081999957561493, -0.9494659900665283], [3.319819927215576, 0.21875, -0.834231972694397], [1.9442698955535889, 0.3629799783229828, -0.30178600549697876], [2.346179962158203, 0.3505859971046448, -0.3855009973049164]], "color": "#cccccc"}, {"polygon": [[-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-11.27489948272705, 0.0, 0.057128001004457474], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478], [-10.50979995727539, 0.0, -0.06933599710464478]], "color": "#cccccc"}, {"polygon": [[-2.8022499084472656, 0.0, 1.500980019569397], [-2.91405987739563, 0.0, 1.4057599306106567], [-2.7475600242614746, 0.0, 1.1728500127792358], [-2.8691399097442627, 0.0, 1.0835000276565552], [-2.6708998680114746, 0.0, 0.9462890028953552], [-1.6791999340057373, 0.0, 0.9619140028953552], [-2.9940998554229736, 0.0, 1.8645399808883667]], "color": "#cccccc"}, {"polygon": [[-0.17431600391864777, -0.6767579913139343, -0.006835999898612499], [-0.3449670076370239, -0.6836680173873901, -0.10785699635744095], [-0.3702789843082428, -0.7496749758720398, -0.23676399886608124]], "color": "#cccccc"}, {"polygon": [[-1.5336899757385254, 0.0, -1.4121099710464478], [-1.300779938697815, 0.0, -1.1342799663543701], [-1.6738299131393433, 0.0, -1.0551799535751343], [-0.5698239803314209, 0.0, -0.90625]], "color": "#cccccc"}, {"polygon": [[-0.17431600391864777, -0.6767579913139343, -0.006835999898612499], [0.025390999391674995, -0.4130859971046448, -0.6538090109825134], [0.053711000829935074, -0.5502930283546448, -0.6528319716453552], [-0.12793000042438507, -0.7719730138778687, -0.005371000152081251]], "color": "#cccccc"}, {"polygon": [[-7.354000568389893, 0.0, 1.0122100114822388], [-7.602540016174316, 0.0, 0.89404296875], [-7.428219795227051, 0.0, 0.69091796875], [-7.73583984375, 0.0, 0.5527340173721313], [-5.729000091552734, 0.0, 0.7001950144767761], [-7.843109607696533, 0.0, 1.5635600090026855]], "color": "#cccccc"}, {"polygon": [[-1.300779938697815, 0.0, -1.1342799663543701], [-1.5336899757385254, 0.0, -1.4121099710464478], [-0.5698239803314209, 0.0, -0.90625], [-1.6738299131393433, 0.0, -1.0551799535751343]], "color": "#cccccc"}, {"polygon": [[3.0852599143981934, 0.12563998997211456, 0.04805399850010872], [3.2346999645233154, 0.09883599728345871, 0.0719280019402504], [3.2316999435424805, 0.11201799660921097, -0.10726999491453171]], "color": "#cccccc"}, {"polygon": [[-4.163569927215576, 0.0, 0.84375], [0.39990198612213135, 0.0, 0.8554689884185791], [0.16943399608135223, 0.5043950080871582, 0.7456049919128418], [-4.154299736022949, 0.3940429985523224, 0.6005859971046448]], "color": "#cccccc"}, {"polygon": [[-12.198599815368652, -5.0999999075429514e-05, -1.700089931488037], [-11.58449935913086, -0.0005859999801032245, -1.023919939994812], [-11.738299369812012, -0.000590000010561198, -1.0317399501800537], [-11.11769962310791, -0.0008340000058524311, -0.4765610098838806], [-11.266599655151367, -0.0008730000117793679, -0.27929601073265076], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478], [-9.037599563598633, 0.0, -0.3818359971046448]], "color": "#cccccc"}, {"polygon": [[-0.17431600391864777, 0.6767579913139343, -0.006835999898612499], [-0.3702789843082428, 0.7496749758720398, -0.23676399886608124], [-0.3449670076370239, 0.6836680173873901, -0.10785699635744095]], "color": "#cccccc"}, {"polygon": [[0.4111329913139343, 0.0, -0.8847659826278687], [0.025390999391674995, -0.4130859971046448, -0.6538090109825134], [-4.108890056610107, -0.3940429985523224, -0.6069340109825134], [-4.100100040435791, 0.0, -0.8486329913139343]], "color": "#cccccc"}, {"polygon": [[-0.17431600391864777, 0.6767579913139343, -0.006835999898612499], [0.16943399608135223, 0.5043950080871582, 0.7456049919128418], [-0.12793000042438507, 0.7719730138778687, -0.005371000152081251]], "color": "#cccccc"}, {"polygon": [[3.671379804611206, -0.09033200144767761, -1.0539599657058716], [0.053711000829935074, -0.5502930283546448, -0.6528319716453552], [0.025390999391674995, -0.4130859971046448, -0.6538090109825134], [0.4111329913139343, 0.0, -0.8847659826278687], [1.212459921836853, 0.0, -0.7765659689903259], [1.5932899713516235, 0.0, -0.7285730242729187], [1.8540000915527344, 0.0, -0.7602530121803284], [2.188969850540161, 0.0, -0.7973629832267761], [3.6835899353027344, 0.0, -1.0622600317001343]], "color": "#cccccc"}, {"polygon": [[0.16943399608135223, 0.5043950080871582, 0.7456049919128418], [1.7575899362564087, 0.5241069793701172, 0.3385530114173889], [1.7043099403381348, 0.5685210227966309, 0.21503600478172302], [0.9577490091323853, 0.617579996585846, 0.3251569867134094], [1.1305400133132935, 0.5116829872131348, 0.05458899959921837], [1.2150800228118896, 0.35741499066352844, 0.0960640013217926], [1.44514000415802, 0.1655990034341812, 0.12918800115585327], [1.9030499458312988, 0.412339985370636, 0.081666000187397], [1.8806999921798706, 0.37229299545288086, 0.36487698554992676], [1.5607199668884277, 0.35426199436187744, 0.6029279828071594], [3.395859956741333, 0.11695799976587296, 0.1768530011177063], [1.7741299867630005, 0.47944098711013794, -0.12415999919176102], [-0.12793000042438507, 0.7719730138778687, -0.005371000152081251]], "color": "#cccccc"}, {"polygon": [[-0.12793000042438507, -0.7719730138778687, -0.005371000152081251], [0.16943399608135223, -0.5043950080871582, 0.7456049919128418], [-0.17431600391864777, -0.6767579913139343, -0.006835999898612499]], "color": "#cccccc"}, {"polygon": [[1.757949948310852, -0.5237460136413574, 0.3385530114173889], [1.704699993133545, -0.5681970119476318, 0.21503600478172302], [1.9033299684524536, -0.41187798976898193, 0.081666000187397], [1.8809599876403809, -0.371847003698349, 0.36487698554992676]], "color": "#cccccc"}, {"polygon": [[-4.154299736022949, -0.3940429985523224, 0.6005859971046448], [-4.132319927215576, -0.6679689884185791, -0.021484000608325005], [-0.9501950144767761, -0.7592769861221313, 0.026366999372839928], [-0.17431600391864777, -0.6767579913139343, -0.006835999898612499], [0.16943399608135223, -0.5043950080871582, 0.7456049919128418]], "color": "#cccccc"}, {"polygon": [[0.39990198612213135, 0.0, 0.8554689884185791], [-4.163569927215576, 0.0, 0.84375], [-4.154299736022949, -0.3940429985523224, 0.6005859971046448], [0.16943399608135223, -0.5043950080871582, 0.7456049919128418]], "color": "#cccccc"}, {"polygon": [[-0.38933300971984863, 0.6569139957427979, -0.41693899035453796], [-0.7519540190696716, 0.9174799919128418, -0.5712890028953552], [-1.456279993057251, 1.3592900037765503, -0.13617800176143646], [-0.3449670076370239, 0.6836680173873901, -0.10785699635744095], [-0.3702789843082428, 0.7496749758720398, -0.23676399886608124]], "color": "#cccccc"}, {"polygon": [[-0.38933300971984863, 0.6569139957427979, -0.41693899035453796], [-0.3449670076370239, 0.6836680173873901, -0.10785699635744095], [-1.456279993057251, 1.3592900037765503, -0.13617800176143646], [-0.7519540190696716, 0.9174799919128418, -0.5712890028953552]], "color": "#cccccc"}, {"polygon": [[1.5607199668884277, 0.35426199436187744, 0.6029279828071594], [1.8806999921798706, 0.37229299545288086, 0.36487698554992676], [1.7575899362564087, 0.5241069793701172, 0.3385530114173889], [0.16943399608135223, 0.5043950080871582, 0.7456049919128418], [0.39990198612213135, 0.0, 0.8554689884185791], [3.5580198764801025, 0.0008030000026337802, 0.1997459977865219], [3.395859956741333, 0.11695799976587296, 0.1768530011177063]], "color": "#cccccc"}, {"polygon": [[3.5580198764801025, 0.0008030000026337802, 0.1997459977865219], [0.39990198612213135, 0.0, 0.8554689884185791], [0.16943399608135223, -0.5043950080871582, 0.7456049919128418], [1.757949948310852, -0.5237460136413574, 0.3385530114173889], [1.8809599876403809, -0.371847003698349, 0.36487698554992676], [1.5616399049758911, -0.35179200768470764, 0.6033110022544861], [3.395939826965332, -0.11546400189399719, 0.1768530011177063]], "color": "#cccccc"}, {"polygon": [[1.757949948310852, -0.5237460136413574, 0.3385530114173889], [0.16943399608135223, -0.5043950080871582, 0.7456049919128418], [-0.12793000042438507, -0.7719730138778687, -0.005371000152081251], [1.7745399475097656, -0.4789620041847229, -0.1236250028014183], [3.395939826965332, -0.11546400189399719, 0.1768530011177063], [1.5616399049758911, -0.35179200768470764, 0.6033110022544861], [1.8809599876403809, -0.371847003698349, 0.36487698554992676], [1.9033299684524536, -0.41187798976898193, 0.081666000187397], [1.445259928703308, -0.16545499861240387, 0.12918800115585327], [1.2153300046920776, -0.35742899775505066, 0.0960640013217926], [1.1309000253677368, -0.5117560029029846, 0.05458899959921837], [0.9581760168075562, -0.6177719831466675, 0.3251569867134094], [1.704699993133545, -0.5681970119476318, 0.21503600478172302]], "color": "#cccccc"}, {"polygon": [[2.6240198612213135, 0.21240200102329254, -0.5051299929618835], [2.7880799770355225, 0.1752929985523224, -0.3747589886188507], [2.843250036239624, 0.19238300621509552, -0.5886260271072388]], "color": "#cccccc"}, {"polygon": [[-0.3702789843082428, -0.7496749758720398, -0.23676399886608124], [-0.38933300971984863, -0.6569139957427979, -0.41693899035453796], [-0.3449670076370239, -0.6836680173873901, -0.10785699635744095], [-0.17431600391864777, -0.6767579913139343, -0.006835999898612499], [-0.9501950144767761, -0.7592769861221313, 0.026366999372839928], [-4.132319927215576, -0.6679689884185791, -0.021484000608325005], [-4.108890056610107, -0.3940429985523224, -0.6069340109825134], [0.025390999391674995, -0.4130859971046448, -0.6538090109825134], [-0.17431600391864777, -0.6767579913139343, -0.006835999898612499]], "color": "#cccccc"}, {"polygon": [[0.025390999391674995, 0.4130859971046448, -0.6538090109825134], [0.4111329913139343, 0.0, -0.8847659826278687], [-4.100100040435791, 0.0, -0.8486329913139343], [-4.108890056610107, 0.3940429985523224, -0.6069340109825134]], "color": "#cccccc"}, {"polygon": [[2.1867098808288574, 0.3035520017147064, -0.11667399853467941], [3.3055098056793213, 0.053449999541044235, 0.07532200217247009], [2.8010900020599365, 0.18559999763965607, 0.12432499974966049], [2.1838200092315674, 0.27913698554039, -0.0370820015668869]], "color": "#cccccc"}, {"polygon": [[3.4643499851226807, 0.0, -0.8161649703979492], [1.944409966468811, -0.22344399988651276, -0.30174198746681213], [1.9444799423217773, -0.3626039922237396, -0.3017309904098511], [2.346179962158203, -0.3505859971046448, -0.3855009973049164], [2.814929962158203, -0.2851560115814209, -0.5656769871711731], [3.8369100093841553, -0.09081999957561493, -0.9494659900665283], [3.8369100093841553, 0.09081999957561493, -0.9494659900665283], [2.814929962158203, 0.2851560115814209, -0.5656769871711731], [2.346179962158203, 0.3505859971046448, -0.3855009973049164], [1.9442698955535889, 0.3629799783229828, -0.30178600549697876], [1.9442899227142334, 0.22382000088691711, -0.3017739951610565]], "color": "#cccccc"}, {"polygon": [[-10.50979995727539, 0.0, -0.06933599710464478], [-10.333499908447266, 0.11425799876451492, -0.06933599710464478], [-11.266599655151367, -0.0008730000117793679, -0.27929601073265076]], "color": "#cccccc"}, {"polygon": [[-10.333499908447266, -0.11425799876451492, -0.06933599710464478], [-10.50979995727539, 0.0, -0.06933599710464478], [-11.266599655151367, -0.0008730000117793679, -0.27929601073265076]], "color": "#cccccc"}]
function range(start, stop, step) {
    // If only one argument is provided, set start to 0 and stop to the value of the argument
    if (arguments.length === 1) {
        stop = start;
        start = 0;
    }
    
    // If step is not provided, default to 1
    step = step || 1;

    // Create an array to hold the range values
    const result = [];

    // Handle negative step
    if (step < 0) {
        for (let i = start; i > stop; i += step) {
            result.push(i);
        }
    } else {
        for (let i = start; i < stop; i += step) {
            result.push(i);
        }
    }

    return result;
}

function hexToRgb(hex) {
    var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
    return result ? {
        r: parseInt(result[1], 16),
        g: parseInt(result[2], 16),
        b: parseInt(result[3], 16)
    } : null;
}

function colorDistance(color1, color2) {
    // Calculate the Euclidean distance between two RGB colors
    return Math.sqrt(
        Math.pow(color1.r - color2.r, 2) +
        Math.pow(color1.g - color2.g, 2) +
        Math.pow(color1.b - color2.b, 2)
    );
}

function getColorLetter(hexColor) {
    const colorMap = {
        '#ff0000': 'r', // red
        '#00ff00': 'g', // green
        '#0000ff': 'b', // blue
        '#ffc0cb': 'p', // pink
        '#ffff00': 'y', // yellow
        '#000000': 'd',
        '#cccccc': 'c'
    };

    // Normalize the input to ensure it starts with a '#' and is in lowercase
    const normalizedColor = hexColor.toLowerCase();

    // If the color is in the map, return the corresponding letter
    if (colorMap[normalizedColor]) {
        return colorMap[normalizedColor];
    }

    // Convert input color to RGB
    const inputRgb = hexToRgb(normalizedColor);

    // Find the most similar color
    let closestColor = null;
    let closestDistance = Infinity;

    for (const [colorHex, letter] of Object.entries(colorMap)) {
        const colorRgb = hexToRgb(colorHex);
        const distance = colorDistance(inputRgb, colorRgb);

        if (distance < closestDistance) {
            closestDistance = distance;
            closestColor = letter;
        }
    }

    return closestColor;
}

function clearMap() {
  // Assuming you have a way to clear the map or reset the grid
  // This function should remove all existing sprites from the screen
  // You may need to implement this based on your specific engine's API
  // For example, if you have a grid or array of sprites, you can reset it here
  // This is a placeholder implementation
  setMap(levels[level]); // Reset to the initial map
}

var size = 4
var offs = 32

function update() {
  // Rotate each vertex of the basefigure
  var rotatedFigure = basefigure.map(face => {
    return {
      ...face,
      polygon: face.polygon.map(vertex => {
        // Rotate the vertex
        let rotatedVertex = rotateX(vertex, rotx);
        rotatedVertex = rotateY(rotatedVertex, roty);
        rotatedVertex = rotateZ(rotatedVertex, rotz);
        return rotatedVertex;
      })
    };
  });

  var todraw = engine.render(rotatedFigure);
  //console.log("todraw:", todraw); // Debugging output
  clearMap()
  for (let face of todraw) {
    //console.log("face:", face); // Debugging output
    for (let i = 0; i < face.polygon.length; i++) {
      let vec1 = face.polygon[i];
      let vec2 = face.polygon[(i + 1) % face.polygon.length]; // Connect to the next vertex
      let x0 = offs + Math.round(vec1[0] * size);
      let y0 = 32 + Math.round(vec1[1] * size);
      let x1 = offs + Math.round(vec2[0] * size);
      let y1 = 32 + Math.round(vec2[1] * size);

      // Bresenham's line algorithm
      let dx = Math.abs(x1 - x0);
      let dy = Math.abs(y1 - y0);
      let sx = (x0 < x1) ? 1 : -1; // Step in x direction
      let sy = (y0 < y1) ? 1 : -1; // Step in y direction
      let err = dx - dy; // Error value

      while (true) {
        //console.log("Adding sprite at:", x0, y0, face.color); // Debugging output
        if ((x0 > 0) && (x0 < 64) && (y0 > 0) && (y0 < 64)) {
          addSprite(x0, y0, getColorLetter(face.color)); // Use face.color directly
        }
        // Check if we've reached the end point
        if (x0 === x1 && y0 === y1) break;

        let err2 = err * 2;
        if (err2 > -dy) {
          err -= dy;
          x0 += sx;
        }
        if (err2 < dx) {
          err += dx;
          y0 += sy;
        }
      }
    }
  }
}
update();

onInput("j", () => {
  rotx++;
  if (rotx > 360) {
    rotx = 0
  }
  update()
})

onInput("k", () => {
  roty++;
  if (roty > 360) {
    roty = 0
  }
  update()
})

onInput("l", () => {
  rotz++;
  if (rotz > 360) {
    rotz = 0
  }
  update()
})

onInput("w", () => {
  size++;
  update()
})

onInput("s", () => {
  if (size > 1) {
    size--;
  }
  update()
})

onInput("a", () => {
  offs++
  update()
})

onInput("d", () => {
  offs--
  update()
})